<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@include file="../common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/page.css">

	<title> <spring:message code="class.page.title"/></title>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/zTree3.3/js/jquery.ztree.core-3.5.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/zTree3.3/js/jquery.ztree.excheck-3.5.js"></script>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/zTree3.3/css/zTreeStyle/zTreeStyle.css" type="text/css">


	<script type="text/javascript">
		var _gridWidth;
		var _gridHeight;
		//页面自适应
		function resizePageSize(){
			_gridWidth = $(document).width()-12;/*  -189 是去掉左侧 菜单的宽度，   -12 是防止浏览器缩小页面 出现滚动条 恢复页面时  折行的问题 */
			_gridHeight = $(document).height()-32-80; /* -32 顶部主菜单高度，   -90 查询条件高度*/
		}


		var data  =  [{
			"id": 0,
			"checked": true,
			"pId": -1,
			"open": true,
			"name": "学生信息管理",
		},
			{
				"id": 1,
				"checked": false,
				"pId": 0,
				"open": true,
				"name": "张三",
			}];



		$(function () {
			var setting = {
				check: {
					enable: false
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback : {
					onCheck : onCheckNode
				}
			};

			$("#shouquanBtn").click(function( event ) {

				$.ajax({
					type : 'POST',
					url : '${pageContext.request.contextPath}/gdpinfo/queryFileInfoZtreeList',
					dataType : 'json',
					cache : false,
					data : [],
					success : function(data) {
						console.log(data);
						$.fn.zTree.init($("#roleTreeID"), setting, data);
					},
					error : function() {
						message("<spring:message code='common.error'/>");
					}
				});
				var setting = {

					check: {
						enable: true,
						chkStyle: "checkbox",
						chkboxType: { "Y": "p", "N": "s" }
					},
					data: {
						simpleData: {
							enable: true}
					},
					callback : {
						beforeCheck : function(treeId, treeNode) {
							var zTree = $.fn.zTree.getZTreeObj("roleTreeID");
							zTree.checkAllNodes(false);
							return true;
						},
						onCheck : function(e, treeId, treeNode) {
							console.log("当前被选择的节点：");
							console.log(treeNode);
							onCheckNode;
						}

					}
				};
				//回调函数
				$("#menuTreeID").dialog( "open" );

			});


			$( "#menuTreeID" ).dialog({
				autoOpen : false,
				width : 400,
				modal : true,
				resizable : false,
				title: "<spring:message code='role.grant'/>",
				buttons: [
					{
						text: "<spring:message code='confirm'/>",
						click: function() {
							var ps = [];
							var treeObj=$.fn.zTree.getZTreeObj("roleTreeID");
							var	nodes=treeObj.getCheckedNodes(true);

							var fn = $("#new_folder-name-id").val();
							if(nodes && nodes.length >0) {
								for (var i = 0; i < nodes.length; i++) {
									ps[i] = nodes[i].id;
								}
							}
							var ids = searchTableColumn($("#flexiGridID"),0);
							$.ajax({
								type : 'POST',
								url : '${pageContext.request.contextPath}/gdpinfo/grantRole',
								dataType : 'json',
								cache : false,
								data : [
									{name : 'nodes', value : ps},
									{name : 'folderName', value : fn}
								],
								success : function(data) {
									$('#flexiGridID').flexReload();
									$("#menuTreeID").dialog( "close" );
									message(data.msg);


								},
								error : function() {
									message("<spring:message code='common.error'/>");
								}
							});

						}
					},
					{
						text: "<spring:message code='common'/>",
						click: function() {
							$( this ).dialog( "close" );
						}
					}
				]
			});

		});


		//将节点保存到数据库
		function onCheckNode(event, treeId, treeNode)
		{
			console.info(treeNode.id);
			// query([{name:"parentId",value:treeNode.id}]);
		}
	</script>


</head>
<body style="display: flex;flex-direction: column">
<!-- 权限树 -->
<a href="#" id="shouquanBtn" class="ui-state-default ui-corner-all cbe-button"><span class="ui-icon ui-icon-plus"></span><spring:message code="role.authorization"/></a>



<!-- 权限树 -->
<div id="menuTreeID" class="zTreeDemoBackground left"
	 title="<spring:message code="role.authorization"/>"  align="center"
	 style="display: none;">
	<input class="form-control" type="text" name="folderName" id="new_folder-name-id">

	<ul id="roleTreeID" class="ztree"></ul>
</div>

</body>
</html>